package com.ray.test.actuator.params;

import com.ray.test.mock.MocKFactory;
import com.ray.test.mock.MockConfig;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author bo shen
 * @Description: 参数模拟构造
 * @Class: ParamsBuilder
 * @Package com.ray.test.actuator.params
 * @date 2019/12/12 14:26
 * @company <p>杭州传化陆鲸科技有限公司</p>
 * @updateRecord time(修改时间)  author(修改人)   desc(修改内容)
 */
@Slf4j
public class ParamsInitBuilder implements Bulider<Class<?>, Object> {

    private static ParamsInitBuilder instance = new ParamsInitBuilder();

    public static ParamsInitBuilder getInstance() {
        return instance;
    }

    @Override
    public Object bulider(Class<?> clazz, Method method, Parameter parameter) {
        Object value = null;
        if (List.class.isAssignableFrom(clazz)) {
            value = MocKFactory.getDataMock(List.class).dataMocker(clazz, method, parameter);
        }else if (Set.class.isAssignableFrom(clazz)) {
            value = MocKFactory.getDataMock(Set.class).dataMocker(clazz, method, parameter);
        } else if (Map.class.isAssignableFrom(clazz)) {
            value = MocKFactory.getDataMock(Map.class).dataMocker(clazz, method, parameter);
        } else if (clazz.isInterface()) {
            value = MocKFactory.getInterfaceDataMock().dataMocker(clazz, method, parameter);
        } else if (clazz.isArray()) {
            value = MocKFactory.getArrayDataMock().dataMocker(clazz, method, parameter);
        }  else {
            value = MocKFactory.getDataMock(null).dataMocker(clazz, method, parameter);
        }
        return value;
    }
}
